package cn.zc.service.impl;

import cn.zc.Scheduled.DynamicScheduleTask;
import cn.zc.Scheduled.PeriodTimeChangeEvent;
import cn.zc.entity.LateTimeCource;
import cn.zc.entity.TimeVo;
import cn.zc.entity.User;
import cn.zc.mapper.AdminMapper;
import cn.zc.mapper.StudentMapper;
import cn.zc.mapper.TimeMapper;
import cn.zc.result.Result;
import cn.zc.service.AdminService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import java.sql.Time;
import java.util.List;
import java.util.Map;

@Service
public class AdminServiceImpl implements AdminService {
    @Autowired
    private AdminMapper adminMapper;
    @Autowired
    private TimeMapper timeMapper;
    @Autowired
    private JdbcTemplate jdbcTemplate;

    @Autowired
    private DynamicScheduleTask dynamicScheduleTask;

    @Autowired
    private ApplicationEventPublisher eventPublisher;

    @Override
    public int getNowTime() {
        return adminMapper.getNowTime();
    }

    @Override
    public void setWeek(int week) {
        adminMapper.setWeek(week);
    }

    @Override
    public List<User> getAdminInfo() {
        return adminMapper.getAdminInfo();
    }

    @Override
    public List<TimeVo> getTime() {
        List<TimeVo> time = timeMapper.getTime();
        return time;
    }

    @Override
    public Result setTime(TimeVo timeVo) {
        adminMapper.setTime(timeVo);
        // 发布事件，通知系统重新设置定时任务
//        eventPublisher.publishEvent(new PeriodTimeChangeEvent(this));
        dynamicScheduleTask.resetTasks();
        return Result.success("修改成功");
    }

    @Override
    public void clearLoginLog() {
        adminMapper.clearLoginLog();
    }

    @Override
    public void deleteAdmin(String id) {
        adminMapper.deleteAdmin(id);
    }

    @Override
    public int overtimelognum(String search,int type) {
        return adminMapper.overtimelognum(search,type);
    }
}
